﻿using System;
using System.Collections.Generic;
using System.Text;

using DevExpress.XtraBars;
using System.Drawing;

namespace Future.FormBase
{
    public class DevBarButtonInfo : IButtonInfo
    {
        private BarButtonItem _btn = null;
        private OnButtonClick _clickEvent = null;

        public DevBarButtonInfo(BarManager barManager, string name, string caption, Image image, Size size, OnButtonClick clickEvent, bool group)
        {
            _btn = new BarButtonItem(barManager, caption);
            _btn.Glyph = image;
            _btn.PaintStyle = BarItemPaintStyle.CaptionGlyph;
            _btn.Name = name;
            _btn.Width = size.Width;
            _clickEvent = clickEvent;
            _btn.ItemClick += new ItemClickEventHandler(OnBarItemClick);
            _Group = group;
        }
        private void OnBarItemClick(object sender, ItemClickEventArgs e)
        {
            if (_clickEvent != null)
                _clickEvent(this);
        }
        private void OnClick(object sender, EventArgs e)
        {
            if (_clickEvent != null) _clickEvent(this);
        }

        #region IButtonInfo 成员

        public string Name { get { return _btn.Name; } set { _btn.Name = value; } }

        public string Caption { get { return _btn.Caption; } set { _btn.Caption = value; } }
        public Image Image { get { return null; } set { } }

        public object Button { get { return _btn; } }
        public object Tag { get { return _btn.Tag; } set { _btn.Tag = value; } }

        private int _Index = -1;
        public int Index { get { return _Index; } set { _Index = value; } }

        public bool Enable { get { return _btn.Enabled; } set { _btn.Enabled = value; } }

        private bool _Group = false;
        public bool Group { get { return _Group; } set { _Group = value; } }

        #endregion
    }

    /// <summary>
    /// 引用NullObject模式,避免程序因访问null对象引发异常
    /// </summary>
    public class NullButton : IButtonInfo
    {
        #region IButtonInfo 成员

        public string Name
        {
            get { return ""; }
            set { }
        }

        public string Caption
        {
            get { return ""; }
            set { }
        }

        public System.Drawing.Image Image
        {
            get { return null; }
            set { }
        }

        public int Index
        {
            get { return 0; }
            set { }
        }

        public object Button
        {
            get { return null; }
        }

        public bool Enable
        {
            get { return false; }
            set { }
        }

        public object Tag
        {
            get { return null; }
            set { }
        }
        public bool Group
        {
            get { return false; }
            set { }
        }
        #endregion
    }
}
